package com.zmc.coupon.infrastructure.bean.vo;

import com.lmax.disruptor.RingBuffer;
import lombok.Data;

/**
 * @Author：zmc
 * @Date：2024/12/30 16:17
 */

@Data
public class CouponHistoryUpdateProducer {

    public RingBuffer<CouponHistoryUpdateProducer> couponHistoryUpdateRingBuffer;

    public Long couponId;

    public CouponHistoryUpdateProducer() {
    }

    public CouponHistoryUpdateProducer(RingBuffer<CouponHistoryUpdateProducer> couponHistoryUpdateRingBuffer, Long couponId) {
        this.couponHistoryUpdateRingBuffer = couponHistoryUpdateRingBuffer;
        this.couponId = couponId;
    }

    public void publish(){
        long sequence = couponHistoryUpdateRingBuffer.next();
        try {
            CouponHistoryUpdateProducer couponHistoryUpdateProducer = couponHistoryUpdateRingBuffer.get(sequence);
            couponHistoryUpdateProducer.setCouponId(this.couponId);
        }finally {
            couponHistoryUpdateRingBuffer.publish(sequence);
        }
    }
}
